package com.example.activity_usage.jump;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.activity_usage.R;

public class JumpStartActivity extends AppCompatActivity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("Activity生命周期-JumpStart", "onCreate");
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_jump_start);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        findViewById(R.id.btn_jump).setOnClickListener(this);

        findViewById(R.id.btn_sendto).setOnClickListener(this);
        findViewById(R.id.btn_dial).setOnClickListener(this);
        findViewById(R.id.btn_call).setOnClickListener(this);
        findViewById(R.id.btn_answer).setOnClickListener(this);
        findViewById(R.id.btn_custom_action).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_jump) {
            Intent intent = new Intent();
            intent.setClass(JumpStartActivity.this, JumpFinishActivity.class);
            startActivity(intent);
        } else if (v.getId() == R.id.btn_call) {
            // 跳转到打电话界面
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_CALL);
            Uri data = Uri.parse("tel:18975864196");
            intent.setData(data);
            startActivity(intent);
        } else if (v.getId() == R.id.btn_dial) {
            // 跳转到拨号界面，并默认在拨号界面输入指定的手机号码
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_DIAL);
            Uri data = Uri.parse("tel:18975864196");
            intent.setData(data);
            startActivity(intent);
        } else if (v.getId() == R.id.btn_sendto) {
            // 跳转到发短信界面
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SENDTO);
            Uri data = Uri.parse("smsto:18975864196");
            intent.setData(data);
            startActivity(intent);
        } else if (v.getId() == R.id.btn_answer) {
            // 跳转到接电话界面
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_ANSWER);
            startActivity(intent);
        } else if (v.getId() == R.id.btn_custom_action) {
            // 跳转到自定义的action（计算器应用的Action，Action在calculator应用的AndroidManifest.xml中定义了）
            // 注意，跳转前必须确保计算器App已经启动，且处于后台进程中
            Intent intent = new Intent();
            intent.setAction("android.intent.action.CALCULATOR");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("Activity生命周期-JumpStart", "onStart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("Activity生命周期-JumpStart", "onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("Activity生命周期-JumpStart", "onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("Activity生命周期-JumpStart", "onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("Activity生命周期-JumpStart", "onDestroy");
    }
}